<template>
  <div class="cartControl">
    <transition name="fade">
      <span @click.stop.prevent="decreaseFood()" v-show="food.count > 0"><i class="iconfont icon-jianhao"></i></span>
    </transition>
    <span class="oneNum" v-show="food.count > 0">{{food.count}}</span>
    <span @click.stop.prevent="addFood($event)"><i class="iconfont icon-comiisjiahao"></i></span>
  </div>
</template>

<script>
  export default {
    props: {
      food: {
        type: Object,
        default(){
          return {}
        }
      }
    },
    methods: {

      decreaseFood(){
        if (this.food.count > 0) {
          this.food.count--;
        }
      },
      addFood(e){
          console.log(this.food.count);
        if (!this.food.count) {
          this.$set(this.food, "count", 1);
        } else {
          this.food.count++;
        }
//        console.log(e.target);
        this.$emit('addClick', e.target)
      }
    }
  }
</script>

<style lang="scss">
  .cartControl {
    position: absolute;
    right: 0;
    font-size: 0;
    span {
      display: inline-block;
      width: 24px;
      height: 24px;
      line-height: 19px;
      text-align: center;
      vertical-align: top;
      font-size: 24px;
    }
    .iconfont {
      color: rgb(0, 160, 220);
    }
    .oneNum {
      font-size: 10px;
      line-height: 24px;
      color: rgb(147, 153, 159);
    }
    .fade-enter-active, .fade-leave-active {
      transition: all .5s;
    }
    .fade-enter, .fade-leave-to {
      opacity: 0;
      transform: translate3d(24px, 0, 0) rotate(180deg);
      transform-origin: center;
    }
  }
</style>
